<template>
	<view>
		<view class="goods-item" >
			<view class="goods-left-images">
				<radio :checked="goods.goods_state" color="#C00000" v-show="showRadio" @click="clickHandler"></radio>
				<image :src="goods.goods_small_logo || defaultPic" class="goods-pic"></image>
			</view>
			<view class="goods-right-info">
				<view class="goods-name">
					{{goods.goods_name}}
				</view>
				<view class="goods-infoBox">
					<view class="goods-price">
						¥{{goods.goods_price | tofixed}}
					</view>
					<uni-number-box :min="1" :value="goods.goods_count" @change="changeValue" v-if="showCount"/>

				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name:"my-goods",
		props:{
			goods:{
				type:Object,
				default:{}
			},
			showRadio:{
				type:Boolean,
				default:false
			},
			showCount:{
				type:Boolean,
				default:false
			}
		},
		data() {
			return {
				defaultPic:'/static/tab-icons/cart-o.png'
			};
		},
		filters:{
				
			tofixed(num){
				return Number(num).toFixed(2)
			}
		},
		methods:{
			clickHandler(){
				this.$emit('radio-change',{
					goods_id:this.goods.goods_id,
					goods_state:!this.goods.goods_state
				})
			},
			changeValue(val){
				this.$emit('num-change',{
					goods_id:this.goods.goods_id,
					goods_count:+val
					
				})
			}
		}
	}
</script>

<style lang="scss">
	.goods-item{
		display: flex;
		padding: 10px 5px;
		border-bottom: 1px solid #efefef;
		.goods-left-images{
			margin-right: 5px;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.goods-pic{
				width: 100px;
				height: 100px;
				display: block;
				
			}
		}
		.goods-right-info{
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			.goods-name{
				font-size: 13px;
			}
			.goods-infoBox{
				display: flex; 
				flex: 1;
				align-items: center;
				justify-content: space-between;
				.goods-price{
					color: #C00000;
					font-size: 16px;
				}
			}
		}
	}
</style>